package com.ly.honor.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;

/**
 * @Author LiYang
 * @Date 2022/11/17 18:19
 * @Version 1.0
 */
@Configuration
public class ThreadPoolConfig {

    public static final String CONSUMER_POOL = "consumerPool";

    @Value("${honor.thread.pool.consumer}")
    private Integer consumerPoolCore;

    @Bean(name = CONSUMER_POOL)
    public Executor eveConsumerPool() {
        return new ThreadPoolExecutor(
                consumerPoolCore,
                consumerPoolCore * 2,
                10,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(500),
                new ThreadFactoryBuilder().setNameFormat("Production-consumer-pool").build()
        );
    }
}
